home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Magnum One
/
Magnum One (Mid-American Digital) (Disc Manufacturing).iso
/
d18
/
tppcx.arc
/
PCX.DOC
< prev
next >
Wrap
Text File
|
1991-01-29
|
26KB
|
562 lines
PCX.TPU - TPv6.0 Object-Oriented unit for displaying or saving PCX format
picture files on Hercules, EGA, VGA, or compatible adapters.
╔═════════╗
║ BasePCX ║█
╚═════════╝█
▀▀▀▀▀▀▀▀▀▀
The BasePCX object provides basic PCX functions that are independant of the
adapter type. This object is used in the abstract to create device dependant
objects.
RESTRICTIONS ─────────────────────────────────────────────────────────────────
This unit is for use only with EGA/ECM, VGA, and Hercules compatible devices.
Extended image files, ones exceeding the displaying device resolution,
cannot be read at this time and will generate a PCXError. Future versions
will handle panning. When reading a file which was created by a higher
resolution device than the device displaying the file, it may still be read
as long as the image dimensions do not exceed the display device resolution.
The image size can be set in the paint program before creating the picture if
you wish to make the PCX file compatible with several devices.
FIELDS ───────────────────────────────────────────────────────────────────────
PCXError PcxError: byte; Read only
Set to constant equivalent if an error is encountered in reading
writing from object.
See: BasePCX.GetPCXError
Loaded Loaded: boolean; Read/Write
Set to false at object initialization, it is set to true after a
picture has been loaded. It tells internal methods that a
picture has been loaded and if the image or portion of the image
is saved as another file, the existing color mapping is written
to the new file.
See: BasePCX.PCXLoaded
Hdr Hdr: Header; Read only
Record containing information pertaining to the picture file. The
record is filled when reading a PCX file from a 128 byte file
header that precedes the actual image data. The last 58 bytes of
the file header are just filler, so these are ignored. The header
record contains the following fields:
Maker: integer;
Code that specifies the picture generating program
conforms to PCX format. PCXError set if incorrect
maker, further methods halted.
Version: integer;
Code stating what PCX format version the following
picture file was created with. PCXError set if incor-
rect version, further methods halted.
Encoding: integer;
Code indicating the compression type of the following
picture file. PCXError set if not run-length encoded,
further methods halted.
bpp: integer;
Number indicating the number of bits per pixel per
plane. Not used in this unit version.
xmn: integer;
Number setting the upper left horizontal coordinate
of following picture.
See: BasePCX.GetXmn
ymn: integer;
Number setting the upper left vertical coordinate of
following picture.
See: BasePCX.GetYmn
xmx: integer;
Number setting the lower right horizontal coordinate
of following picture.
See: BasePCX.GetXmx
ymx: integer;
Number setting the lower right vertical coordinate of
following picture.
See: BasePCX.GetYmx
HRes: integer;
Number indicating the horizontal resolution of the
device that the created the picture file.
VRes: integer;
Number indicating the vertical resolution of the
device that created the picture file.
CMap: TripletArray;
2-dimensional array ( 16 triplets ) containing palette
information for the following picture. If the
following image is color and the displaying device
is an EGA/VGA, the color map is used and the palette
is set accordingly, if requested in the Show method.
Otherwise CMap is ignored.
Reserved: byte;
Filler number reserved by ZSoft.
NPlanes: byte;
Number of picture planes used to create the image.
Essentially establishes the differance between a mono
and color picture.
See: BasePCX.IsMultiPlane
NBpl: integer;
Number telling the object how many bytes are used to
store a single horizontal line of the picture in
memory.
Palett: integer;
Number for interpreting the palette. 0 = gray scale
iamge. 1 = color image.
Page Page: byte; Read only
Used when reading PCX files, it determines which video page the
image is written to. Since the object uses direct memory, the
picture is written to the page requested regardless of the
active page setting. The visual page setting still maintains
display control.
PFile PFile: pointer; Read only
Points to dynamic memory area where entire PCX file has been
read into ram. This increases decoding speed by reading the
compressed image data from ram instead of thru file I/O.
PCXError will be set if there is not enough memory available.
See: BasePCX.Done
SizeF SizeF: longint; Read only
Size of PCX file read into ram. Used for disposing memory when
destructing the object.
Buf Buf: PBuf; Read only
Pointer to dynamic variable (128 byte) which holds one complete
decoded/encoded scan line during the decoding or encoding
method.
Offset Offset: POffset; Read only
One-dimensional 480 byte array holding the video memory offset
address to the beginning of each horizontal scan line. The
offsets are calculated based on the object and not the creating
device.
Display Display: DisplayRec; Read/Write
Record variable set by descendant objects upon initialization
containing display adapter information. Correct information is
set based on the descendant type and not the creating device.
The record contains the following fields:
SegBase: word;
Base address to video memory.
Page0: word;
Offset from SegBase for start of video page 0.
Page1: word;
Offset from SegBase for start of video page 1.
HorizRes: integer;
Horizontal resolution of specific adapter.
Informative only, not used.
VertRes: integer;
Vertical resolution of specific adapter.
Informative only, not used.
BytesPerLine: integer;
Number of bytes required for one scan line per plane.
Informative only, not used. See: Hdr field.
NoColors: integer;
Number of palette entries available.
Informative only, not used.
f f: file; Read only
Assigned to PCX file and used during decoding or encoding.
During decoding, the file variable is closed immediately after
reading into ram. While encoding, however, the file must remain
open until the process is completed thus requiring it to be a
field of the object.
METHODS, PUBLIC ──────────────────────────────────────────────────────────────
Init constructor Init;
Initializes all internal pointers to nil. Calls the FillOffsets
procedure. Sets PCXError to PCXError0.
OverRide: Always
Done destructor Done; virtual;
Disposes of the Offset and PFile allocations.
OverRide: Mostly
Show procedure Show( Filename: FStr; PageNo: byte; UsePal: boolean );
Displays requested PCX file as assigned by Filename on the page
specified by PageNo (0 or 1 only) using the color mapping as
specified in the PCX file header if UsePal is set to true. If
errors are encountered, PCXError is set accordingly and the
procedure is exited. Only pages 0 and 1 are valid in this version.
If UsePal is set to false, the object uses the default settings
as specified in the EGA_Pal constant. These settings are the same
as a paint program's default settings.
Any PCX file created on a Hercules, EGA, or VGA adapter can be
displayed on any one of the same adapters. That is to say, you
can display a monochrome image on an EGA adapter, or display an
EGA image on a Hercules adapter, or etc. with the following
limitations/conditions: The PCX file vertical size cannot exceed
the display adapter's resolution. Images will be distorted when
displayed on an adapter differant then the creating device. When
displaying a mono picture on a color adapter, set UsePal to
false.
It is important to note the following: When UsePal is set to
true, the PCX file may change the palette. All occurances of a
specific color within the program will be immediately set to the
new value. Also, the object instance does not reset the palette
when it it destructed. It remains more versatile to control the
palette outside the object. Some paint programs, for unknown
reasons, do some strange things with the palette settings. So if
a display doesn't turn out as expected, try setting UsePal to
false. See EGA.DOC for procedure on resetting the palette to the
default condition. See also: BasePCX.Save
This method calls OpenFile; if the file opens without errors,
calls GetHeader, SetPal (if requested), Decode.
See also: BasePCX Page field description
Save procedure Save( x1, y1, x2, y2: integer; Filename: FStr );
Saves image in viewport specified by upper left coordinates
(x1,y1) and lower right coordinates (x2,y2) to disk in PCX format
with the specified Filename. At this time, it saves only an image
displayed on page 0 of any adapter. If a PCX picture has been
previously loaded and all/portion of the same picture is being
saved, the same color mapping information is written to the new
file IF it was displayed with UsePal set to true AND the object
was not destructed between the calls to Show and Save. Otherwise
the default EGA palette is written. This method is graphics
adapter specific, the correct object must be used depending on
the graphics card of creating device. A VGA adapter can be set to
640x350 or 640x480 resolution. It is important to note that the
image saved will, most of the time, not be to the exacting
coordinates specified. This is due to the fact that each bit
represents one pixel (8 pixels per byte). Since there are always
an integral number of bytes, the image must start and stop at
multiples of 8.
This method calls OpenFile with a newfile request; if no errors
are reported, calls WriteHeader, Encode.
See also: BasePCX.Show
GetPicVp procedure GetPicVp( var PicVp: viewporttype );
Returns displayed image boundaries in the PicVp variable. These
coordinates are read from the PCX header information.
GetXmn function GetXmn: integer;
Returns upper left horizontal corner of picture.
GetYmn function GetYmn: integer;
Returns upper left vertical corner of picture.
GetXmx function GetXmx: integer;
Returns lower right horizontal corner of picture.
GetYmx function GetYmx: integer;
Returns lower right vertical corner of picture.
IsMulti-
Plane function IsMultiPlane: boolean;
Returns true if picture read is a multi-plane image. Generally
used to determine the differance between a color or B/W image.
GetPCXError function GetPCXError: byte;
Returns with numeric code cooresponding to type of error
encountered during object implementation, if any, and can be
compared to the following constants:
0 = No error
1 = File not found
2 = Not enough memory for picture buffer
3 = Error reading PCX file into RAM
4 = Multi-plane image encountered,display adapter for
single plane only
5 = Not a valid PCX file
6 = Incorrect PCX version. Must be v3.0 or greater
7 = Not enough memory for Offset Buffer
8 = Unable to open new file
9 = Encoding error
10 = Image exceeds 64k limit.
11 = Image exceeds display capabilities.
PCXLoaded function PCXLoaded: boolean;
Returns true if a PCX picture has been loaded from disk and is
currently displayed. ( whether invisble or not ) Primarily used
internally for resetting the EGA.
METHODS, PRIVATE ─────────────────────────────────────────────────────────────
OpenFile procedure OpenFile( Filename: FStr; NewFile: boolean;
var Ok: boolean );
Opens requested PCX file. When reading a file, Newfile is set
to false and the file is read into ram and then closed. When
writing a file, NewFile is set to true and the file is
rewritten. No action is taken if the file currently exists and
the method overwrites, always. Action should be taken prior to
writing a PCX file to determine if an existing file exists. Ok
returns true if normal file procedures (IOResult) performed
correctly.
GetHeader procedure GetHeader;
When reading a PCX file, method decodes header information and
sets internal fields accordingly.
SetPal procedure SetPal; virtual;
Abstract method only.
OverRide: Always
Decode procedure Decode; virtual;
Abstract method only.
OverRide: Always
DecodeRow procedure DecodeRow( var Index: integer );
Decodes compressed image data contained in the memory area
pointed to by Buf. Index is a counter variable keeping track of
the current position in memory pointed to by PFile.
WriteRow procedure WriteRow( row: integer );
Writes uncompressed image data to video memory at the page
requested and plane setting. The row cooresponds to the Offset
array index for addressing.
ReadRow procedure ReadRow( row, sbyt: integer; var inBuf: PBuf );
Reads a single scan line, starting at offset row + sbyt, into the
inBuf variable based on the row requested and plane setting. Row
cooresponds to the Offset array index for addressing. Sbyt is
the byte number within the row to start reading from.
WriteHeader procedure WriteHeader;
Writes header infromation to a new PCX file. Palette information
is written as a default configuration, normal to the creating
device. Future versions will allow for palette manipulation.
FillOffsets function FillOffsets: boolean; virtual;
Abstract method only.
OverRide: Always.
Encode function Encode(SRow, ERow: integer; sbyt: byte): integer;virtual;
Abstract method only.
OverRide: Always
EncPut function EncPut( byt, cnt: byte ): integer;
Writes a data byte (byt) to the PCX file (f). Cnt is a repeat
rate of the data byte. If the repeat rate is greater than one,
the cnt variable is coded and written to the file prior to the
data byte. EncPut returns with the number of bytes written to
the file (1 or 2) for keeping track of the total number written.
EncodeLine function EncodeLine( inBuf: PBuf; inLen: integer ): boolean;
Compresses the data contained in the inBuf variable. The amount
of data to compress is determined by the inLen variable. Reads
the data in inBuf a byte at a time and counts the number of
times the data is repeated, if any. It calls EncPut when the
data stops repeating (byte mismatch) to write to the PCX file.
EncodeLine returns true if the encoding process was successful.
GetByte function GetByte( n: integer ): byte;
Retrieves the byte value from the memory pointed to by PFile at
position n.
GetInteger function GetInteger( n1, n2: integer ): integer;
Retrieves the integer value from the memory pointed to by PFile
at positions n1 and n2.
FillOffsets function FillOffsets: boolean; virtual;
First determines if enough memory is available for reading the PCX
file into ram, then calculates video memory offset addresses based
on descendant type. Calculations are stored in the Offset field
with each horizontal scan line number cooresponding with the
array number. ie: scanline 0 = Offset[0], scanline 1 = Offset[1]
Method returns true if memory was allocated. If not enough
memory is available, the method returns false and the Init
constructor fails, returning NIL to the host.
Decode procedure Decode; virtual;
Decodes compressed image data based on header information.
Allocates memory for Buf, determines if image is multiplane,
calls EGA_SetPlane_Write, DecodeRow, WriteRow.
OverRide: Always
┌─────────┐
│ BasePCX │
└────┬────┘
┌─────┘
╔════╧════╗
║ HercPCX ║█
╚═════════╝█
▀▀▀▀▀▀▀▀▀▀
The HercPCX object provides the device dependant methods for creating PCX
format files on Hercules graphics adapters. It can create PCX files on any
monochrome graphics devices whose base video address is $B000, however if
multiple pages are not supported you must be sure to pass only page 0 to the
inherited Show method.
METHODS, PUBLIC ──────────────────────────────────────────────────────────────
Init constructor Init;
Checks for the presence of an EGA/VGA adapter by seeing if the
EGACard variable in the EGA unit is true or false. If EGACard is
true the Init contructor fails, since a HercPCX instance on an
EGA/VGA adapter would not display properly. If an EGA/VGA is not
detected, the PCX units Display constant is set to equal the
HERC_Attr constant and BasePCX.Init is called. If the
BasePCX.Init method returns false, this constructor fails.
Done destructor Done; virtual;
Calls BasPCX.Done destructor.
METHODS, PRIVATE ─────────────────────────────────────────────────────────────
Decode procedure Decode; virtual;
Allocates/disposes of memory for the Buf pointer.
Checks with the IsMultiPlane method and if true decodes the
compressed data based on a multi-plane image else decodes
normally. Loops thru DecodeRow and WriteRow for each scan line
from Hdr.ymn to Hdr.ymx.
GetRow procedure GetRow( r, sbyt: integer; var inBuf: PBuf );
Calls ReadRow with r (row to read), sbyt (starting byte in row),
and inBuf (memory area to read into).
Encode function Encode(SRow, ERow: integer; sbyt: byte): integer;virtual;
Loops from SRow to ERow calling GetRow with scan line number
cooresponding to the loop count and sbyt starting postion. Calls
EncodeLine with the data retrieved from GetRow. If EncodeLine
returned true, goes to top of loop, else sets itself to PCXError9
and exits. If Encode completes correctly it returns to the calling
method set to 0.
FillOffsets function FillOffsets: boolean; virtual;
Fills the Offset variable with the video memory address to the
start of each scan line. The Offset array elements coorespond to
the scan line number. ie: Offset^[0] = scan line 0, Offset^[1] =
scan line 1, etc. These addresses are calculated based on the
Hercules graphics adapter, which is in an interlaced pattern.
┌─────────┐
│ BasePCX │
└────┬────┘
┌─────┴─────┐
┌────┴────┐ ╔════╧════╗
│ HercPCX │ ║ EgaPCX ║█
└─────────┘ ╚═════════╝█
▀▀▀▀▀▀▀▀▀▀
The EgaPCX object provides the device dependant methods for reading or
creating PCX format files on EGA/VGA graphics adapters on pages 0 and 1 only
in 640 x 350 resolution mode.
METHODS, PUBLIC ──────────────────────────────────────────────────────────────
Init constructor Init;
Checks with EGA unit's EGACard constant and if not true, the
constructor Fails. If EGACard returns true, Display is set to
EGA_Attr and BasePcx.Init is called.
Done destructor Done; virtual;
Calls BasePCX.Done destructor.
METHODS, PRIVATE ─────────────────────────────────────────────────────────────
SetPal procedure SetPal; virtual;
Sets palette to values contained in Hdr.CMap as read from the
PCX file header. Calls EGA unit, EGA_SetRGBPalette procedure
with Hdr.CMap component values.
Decode procedure Decode; virtual;
Allocates/disposes of memory for the Buf pointer.
Checks with the IsMultiPlane method and if true decodes the
compressed data based on a multi-plane image else decodes
according to single plane data. Loops thru DecodeRow and WriteRow
for each scan line from Hdr.ymn to Hdr.ymx.
GetRow procedure GetRow( Plane, r, sbyt: integer; var inBuf: PBuf );
Retrieves video memory data for compressing.
Calls EGA unit, EGA_SetPlane_Read with Plane (bit plane to read),
calls ReadRow with r (scanline/row to read), sbyt (starting byte
in row) and inBuf (memory area to read into).
Encode function Encode(SRow, ERow: integer; sbyt: byte): integer;virtual;
Loops from SRow to ERow calling GetRow with scan line number
cooresponding to the loop count and sbyt starting position. Calls
EncodeLine with the data retrieved from GetRow. If EncodeLine
returned true, goes to top of loop, else sets itself to PCXError9
and exits. If Encode completes correctly it returns to the calling
method set to 0.
FillOffsets function FillOffsets: boolean; virtual;
Fills the Offset variable with the video memory address to the
start of each scan line. The Offset array elements coorespond to
the scan line number. ie: Offset^[0] = scan line 0, Offset^[1] =
scan line 1, etc. These addresses are calculated based on the
EGA/VGA graphics adapter, which is in a non-interlaced pattern.
┌─────────┐
│ BasePCX │
└────┬────┘
┌─────┴─────┐
┌────┴────┐ ┌────┴────┐
│ HercPCX │ │ EgaPCX │
└─────────┘ └────┬────┘
╔════╧════╗
║ VgaPCX ║█
╚═════════╝█
▀▀▀▀▀▀▀▀▀▀
The VgaPCX object provides the device dependant methods for reading or
creating PCX format files on VGA graphics adapters on pages 0 and 1 only
in 640 x 350 or 640 x 480 resolution modes.
Init constructor Init;
Checks with EGA unit's VGACard constant and if not true, the
constructor Fails. If VGACard returns true, Display is set to
EGA_Attr with VertRes set to 480 and BasePcx.Init is called.
Done destructor Done; virtual;
Calls BasePCX.Done destructor.
──────────────────────────────────────────────────────────────────────────────
Compiled with Borland's Turbo Pascal v6.0
Designed for ZSoft Corporation's PCX file format
29Jan91